using System;
using System.Linq;
using System.Data;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using Widgetsphere.Core.DataAccess;
using Widgetsphere.Core.Util;
using Widgetsphere.Core.Logging;
using Widgetsphere.Core.Exceptions;
using ACME.Northwind.Business;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Business.Rules;
using ACME.Northwind.Business.SelectCommands;
using System.IO;
using System.Data.SqlClient;

namespace ACME.Northwind.Domain.Objects
{
	#region internal class
	/// <summary>
	/// This is an customizable extender for the domain class associated with the 'Order' object collection
	/// </summary>
	[Serializable()]
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	partial class DomainOrderCollection : PersistableDomainCollectionBase, IEnumerable, ISerializable, IDisposable
	{
		#region Member Variables

		//Generated Relationships This Object Plays Parent Role
		internal bool OrderDetailFilled = false;


		#endregion

		#region ISerializable Members
		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected DomainOrderCollection(SerializationInfo info, StreamingContext context):this()
		{
			OrderDetailFilled = (bool)info.GetValue("OrderDetailFilled", typeof(bool));

		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("OrderDetailFilled", OrderDetailFilled);

		}
		#endregion

		#region Properties

		internal SubDomain SubDomain
		{
			get{ return (SubDomain)this.DataSet; }
		}

		internal string Modifier
		{
			get{ return SubDomain.Modifier; }
		}

		internal virtual DataRelation OrderOrderDetailRelation
		{
			get
			{
				if(!this.OrderDetailFilled)
				{
					OrderDetailSelectByOrderPks retrieveRule = new OrderDetailSelectByOrderPks();
					this.SubDomain.AddSelectCommand(retrieveRule);
					this.SubDomain.RunSelectCommands();
				}
				return this.SubDomain.Relations["OrderOrderDetailRelation"];
			}
		}

		internal virtual DataRelation CustomerOrderRelation
		{
			get
			{
				if(!this.SubDomain.Relations.Contains("CustomerOrderRelation"))
				{
					this.SubDomain.AddCollection(Collections.CustomerCollection);
				}
				return this.SubDomain.Relations["CustomerOrderRelation"];
			}
		}

		internal virtual DataRelation EmployeeOrderRelation
		{
			get
			{
				if(!this.SubDomain.Relations.Contains("EmployeeOrderRelation"))
				{
					this.SubDomain.AddCollection(Collections.EmployeeCollection);
				}
				return this.SubDomain.Relations["EmployeeOrderRelation"];
			}
		}

		internal virtual DataRelation ShipperOrderRelation
		{
			get
			{
				if(!this.SubDomain.Relations.Contains("ShipperOrderRelation"))
				{
					this.SubDomain.AddCollection(Collections.ShipperCollection);
				}
				return this.SubDomain.Relations["ShipperOrderRelation"];
			}
		}

		//Generate Property Access To Related Tables
		internal virtual DomainOrderDetailCollection RelatedOrderDetailCollection
		{
			get { return (DomainOrderDetailCollection)this.SubDomain.GetDomainCollection(Collections.OrderDetailCollection); }
		}

		internal virtual DomainCustomerCollection RelatedCustomerCollection
		{
			get { return (DomainCustomerCollection)this.SubDomain.GetDomainCollection(Collections.CustomerCollection); }
		}

		internal virtual DomainEmployeeCollection RelatedEmployeeCollection
		{
			get { return (DomainEmployeeCollection)this.SubDomain.GetDomainCollection(Collections.EmployeeCollection); }
		}

		internal virtual DomainShipperCollection RelatedShipperCollection
		{
			get { return (DomainShipperCollection)this.SubDomain.GetDomainCollection(Collections.ShipperCollection); }
		}

		//Generated Domain Properties Where This Object Plays Both Roles

		#endregion

		#region Contructors /Initialization

		internal DomainOrderCollection()
		{
			try
			{
				base.TableName = "OrderCollection";
				this.InitClass();
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		private void InitClass() 
		{
			BeginInit();
			this.columnShipVia = new DataColumn("ShipVia", typeof(int), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipVia);
			this.columnShipVia.Caption = "";
			this.columnShipRegion = new DataColumn("ShipRegion", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipRegion);
			this.columnShipRegion.Caption = "";
			this.columnShipPostalCode = new DataColumn("ShipPostalCode", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipPostalCode);
			this.columnShipPostalCode.Caption = "";
			this.columnShippedDate = new DataColumn("ShippedDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShippedDate);
			this.columnShippedDate.Caption = "";
			this.columnShipName = new DataColumn("ShipName", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipName);
			this.columnShipName.Caption = "";
			this.columnShipCountry = new DataColumn("ShipCountry", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipCountry);
			this.columnShipCountry.Caption = "";
			this.columnShipCity = new DataColumn("ShipCity", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipCity);
			this.columnShipCity.Caption = "";
			this.columnShipAddress = new DataColumn("ShipAddress", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnShipAddress);
			this.columnShipAddress.Caption = "";
			this.columnRequiredDate = new DataColumn("RequiredDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnRequiredDate);
			this.columnRequiredDate.Caption = "";
			this.columnOrderId = new DataColumn("OrderID", typeof(int), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnOrderId);
			this.columnOrderId.AllowDBNull = false;
			this.columnOrderId.AutoIncrement = true;
			this.columnOrderId.AutoIncrementSeed = -1;
			this.columnOrderId.AutoIncrementStep = -1;
			this.columnOrderId.Caption = "";
			this.columnOrderDate = new DataColumn("OrderDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnOrderDate);
			this.columnOrderDate.Caption = "";
			this.columnFreight = new DataColumn("Freight", typeof(decimal), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnFreight);
			this.columnFreight.DefaultValue = Decimal.MinValue;
			this.columnFreight.Caption = "";
			this.columnEmployeeId = new DataColumn("EmployeeID", typeof(int), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnEmployeeId);
			this.columnEmployeeId.Caption = "";
			this.columnCustomerId = new DataColumn("CustomerID", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCustomerId);
			this.columnCustomerId.Caption = "";
			this.columnModifiedBy = new DataColumn("ModifiedBy", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnModifiedBy);
			this.columnModifiedDate = new DataColumn("ModifiedDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnModifiedDate);
			this.columnCreatedBy = new DataColumn("CreatedBy", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCreatedBy);
			this.columnCreatedDate = new DataColumn("CreatedDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCreatedDate);
			this.columnTimeStamp = new DataColumn("TimeStamp", typeof(System.Byte[]), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnTimeStamp);
			base.Constraints.Add(new UniqueConstraint("PrimaryKey", new DataColumn[] {this.columnOrderId}, true));
			EndInit();
		}

		private bool mModifyUpdateOn = true;

		/// <summary>
		/// Raises the RowChanged event.
		/// </summary>
		protected override void OnRowChanged(DataRowChangeEventArgs e)
		{
			base.OnRowChanged(e);
			if(e.Action == DataRowAction.Change && mModifyUpdateOn)
			{
				mModifyUpdateOn = false;
				if ((e.Row[this.ModifiedByColumn] == System.DBNull.Value) || ((string)e.Row[this.ModifiedByColumn] != this.Modifier)) e.Row[this.ModifiedByColumn] = this.Modifier;
				mModifyUpdateOn = true;
			}
		}

		#endregion

		#region Database Retrieval

		internal DomainOrder NewItem()
		{
			DomainOrder retval = (DomainOrder)(base.NewRow());
			((DataRow)retval)[ModifiedByColumn] = this.Modifier;
			((DataRow)retval)[ModifiedDateColumn] = DateTime.Now;
			((DataRow)retval)[CreatedByColumn] = this.Modifier;
			((DataRow)retval)[CreatedDateColumn] = DateTime.Now;
			((DataRow)retval)[FreightColumn] = "0";

			return retval;
		}

		internal DomainOrder NewItem(int orderid)
		{
			DomainOrder retval = (DomainOrder)(base.NewRow());
			((DataRow)retval)["OrderID"] = orderid;
			((DataRow)retval)[ModifiedByColumn] = this.Modifier;
			((DataRow)retval)[ModifiedDateColumn] = DateTime.Now;
			((DataRow)retval)[CreatedByColumn] = this.Modifier;
			((DataRow)retval)[CreatedDateColumn] = DateTime.Now;
			((DataRow)retval)[FreightColumn] = "0";

			return retval;
		}

		internal void AddItem(DomainOrder item)
		{
			base.Rows.Add(item);
		}

		internal void InsertAtOrder(DomainOrder item, int pos)
		{
			base.Rows.InsertAt(item, pos);
		}

		internal virtual void Persist()
		{
			this.SubDomain.Persist();
		}

		#region Select Methods

		internal static DomainOrderCollection RunSelect(OrderSearch search, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new OrderSelectBySearch(search));
			sd.RunSelectCommands();
			return (DomainOrderCollection)sd.GetDomainCollection(Collections.OrderCollection);
		}

		internal static DomainOrderCollection RunSelect(OrderSearch search, OrderPaging paging, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			OrderSelectBySearch command = new OrderSelectBySearch(search, paging);
			sd.AddSelectCommand(command);
			sd.RunSelectCommands();
			paging.RecordCount = command.Count;
			return (DomainOrderCollection)sd.GetDomainCollection(Collections.OrderCollection);
		}

		internal static DomainOrderCollection RunSelect(string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new OrderSelectAll());
			sd.RunSelectCommands();
			return (DomainOrderCollection)sd.GetDomainCollection(Collections.OrderCollection);
		}

		internal static DomainOrderCollection RunSelect(int page, int pageSize, string orderByColumn, bool ascending, string filter, out int count, string modifier)
		{
			DomainOrderCollection returnVal = null;
			SubDomain sd = new SubDomain(modifier);
			OrderPagedSelect retrieveRule = new OrderPagedSelect(page, pageSize, PersistableDomainCollectionBase.DataColumnNameToParameterName(orderByColumn), ascending, filter);
			sd.AddSelectCommand(retrieveRule);
			sd.RunSelectCommands();
			returnVal = (DomainOrderCollection)sd.GetDomainCollection(Collections.OrderCollection);
			count = retrieveRule.Count;
			return returnVal;
		}

		internal static DomainOrderCollection SelectByOrderPks(List<OrderPrimaryKey> primaryKeys, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new OrderSelectByPks(primaryKeys));
			sd.RunSelectCommands();
			return (DomainOrderCollection)sd.GetDomainCollection(Collections.OrderCollection);
		}

		#endregion

		#endregion

		#region DomainOrder Collection Methods
		internal void RemoveOrder(DomainOrder item) 
		{
			base.Rows.Remove(item);
		}

		internal virtual int Count 
		{
			get { return base.Rows.Count; }
		}

		/// <summary>
		/// Returns an enumerator that can be used to iterate through the collection.
		/// </summary>
		/// <returns>An Enumerator that can iterate through the objects in this collection.</returns>
		public virtual System.Collections.IEnumerator GetEnumerator() 
		{
			return base.Rows.GetEnumerator();
		}

		/// <summary>
		/// Gets or sets the element at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index of the element to get or set. </param>
		/// <returns>The element at the specified index.</returns>
		internal DomainOrder this[int index] 
		{
			get { return ((DomainOrder)(base.Rows[index])); }
		}

		internal DomainOrder GetOrder(int orderid)
		{
			return ((DomainOrder)(base.Rows.Find(new object[] {orderid})));
		}

		#endregion

		#region Data Columns Setup
		protected DataColumn columnShipVia;
		protected DataColumn columnShipRegion;
		protected DataColumn columnShipPostalCode;
		protected DataColumn columnShippedDate;
		protected DataColumn columnShipName;
		protected DataColumn columnShipCountry;
		protected DataColumn columnShipCity;
		protected DataColumn columnShipAddress;
		protected DataColumn columnRequiredDate;
		protected DataColumn columnOrderId;
		protected DataColumn columnOrderDate;
		protected DataColumn columnFreight;
		protected DataColumn columnEmployeeId;
		protected DataColumn columnCustomerId;
		protected DataColumn columnCreatedBy;
		protected DataColumn columnCreatedDate;
		protected DataColumn columnModifiedBy;
		protected DataColumn columnModifiedDate;
		protected DataColumn columnTimeStamp;
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipViaColumn 
		{
			get { return this.columnShipVia; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipRegionColumn 
		{
			get { return this.columnShipRegion; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipPostalCodeColumn 
		{
			get { return this.columnShipPostalCode; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShippedDateColumn 
		{
			get { return this.columnShippedDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipNameColumn 
		{
			get { return this.columnShipName; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipCountryColumn 
		{
			get { return this.columnShipCountry; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipCityColumn 
		{
			get { return this.columnShipCity; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ShipAddressColumn 
		{
			get { return this.columnShipAddress; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn RequiredDateColumn 
		{
			get { return this.columnRequiredDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn OrderIdColumn 
		{
			get { return this.columnOrderId; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn OrderDateColumn 
		{
			get { return this.columnOrderDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn FreightColumn 
		{
			get { return this.columnFreight; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn EmployeeIdColumn 
		{
			get { return this.columnEmployeeId; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn CustomerIdColumn 
		{
			get { return this.columnCustomerId; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn ModifiedDateColumn 
		{
			get { return this.columnModifiedDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn ModifiedByColumn 
		{
			get { return this.columnModifiedBy; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn CreatedDateColumn 
		{
			get { return this.columnCreatedDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn CreatedByColumn 
		{
			get { return this.columnCreatedBy; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn TimeStampColumn 
		{
			get { return this.columnTimeStamp; }
		}

		#endregion

		#region Protected Overrides

		/// <summary>
		/// Create a new instance of this object type
		/// </summary>
		protected override DataTable CreateInstance()
		{
			return new DomainOrderCollection();
		}

		/// <summary>
		/// Create new row from a DataRowBuilder
		/// </summary>
		/// <param name="builder">The DataRowBuilder object that is used to create the new row</param>
		/// <returns>A new datarow of type 'Order'</returns>
		protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
		{
			DomainOrder retval = new DomainOrder(builder);
			return retval;
		}

		/// <summary>
		/// Returns the type of the datarow that this collection holds
		/// </summary>
		protected override System.Type GetRowType() 
		{
			return typeof(DomainOrder);
		}
		#endregion

		#region Implement Persistable Table Abstact Methods

		/// <summary>
		/// Gets a list of parameters for SQL update commands.
		/// </summary>
		protected override List<IDbDataParameter> GetUpdateFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Gets a list of parameters for SQL insert commands.
		/// </summary>
		protected override List<IDbDataParameter> GetInsertFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Gets a list of parameters for SQL delete commands.
		/// </summary>
		protected override List<IDbDataParameter> GetDeleteFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Determines if the stored procedure or SQL text is used for CRUD operations.
		/// </summary>
		protected override bool UseStoredProcedure
		{
			get { return true; }
		}

		/// <summary>
		/// The stored procedure name that performs deletes for the objects in this collection
		/// </summary>
		protected override string DeleteStoredProcedureName
		{
			get { return "gen_OrderDelete"; }
		}

		/// <summary>
		/// The SQL that performs deletes for the objects in this collection
		/// </summary>
		protected override string DeleteSQLText
		{
			get { return null; }
		}

		/// <summary>
		/// The stored procedure name that performs inserts for the objects in this collection
		/// </summary>
		protected override string InsertStoredProcedureName
		{
			get { return "gen_OrderInsert"; }
		}

		/// <summary>
		/// The SQL that performs inserts for the objects in this collection
		/// </summary>
		protected override string InsertSQLText
		{
			get { return null; }
		}

		/// <summary>
		/// The stored procedure name that performs updates for the objects in this collection
		/// </summary>
		protected override string UpdateStoredProcedureName
		{
			get { return "gen_OrderUpdate"; }
		}

		/// <summary>
		/// The SQL that performs updates for the objects in this collection
		/// </summary>
		protected override string UpdateSQLText
		{
			get { return null; }
		}

		public override void SetChildSelectedFalse()
		{
			OrderDetailFilled = false;
		}

		/// <summary>
		/// Creates the referential integrity for this collection
		/// </summary>
		public override void CreateRelations()
		{
			if(!SubDomain.Relations.Contains("OrderOrderDetailRelation"))
			{
				if(SubDomain.Contains(Collections.OrderDetailCollection))
				{
					DataRelation orderOrderDetailRelation = new DataRelation("OrderOrderDetailRelation",new DataColumn[]{OrderIdColumn}, new DataColumn[]{RelatedOrderDetailCollection.OrderIdColumn});
					SubDomain.Relations.Add(orderOrderDetailRelation);
				}
			}

		}

		bool _handlingError = false;
		/// <summary>
		/// Determines if errors are handled by this object
		/// </summary>
		public override bool HandleErrors()
		{
			if (_handlingError) return false;
			_handlingError = true;
			try
			{
			DataRow[] rowsInError = this.GetErrors();
			List<CustomerPrimaryKey> CustomerPrimaryKeys = new List<CustomerPrimaryKey>();
			List<EmployeePrimaryKey> EmployeePrimaryKeys = new List<EmployeePrimaryKey>();
			List<ShipperPrimaryKey> ShipperPrimaryKeys = new List<ShipperPrimaryKey>();

			foreach(DomainOrder item in rowsInError)
			{
				item.ClearErrors();
				if((item.ParentCol.SubDomain.Contains(ACME.Northwind.Business.Collections.CustomerCollection)) &&
					item.CustomerItem == null)
				{
					if(item.CustomerId != null)
					{
					CustomerPrimaryKey newKey = new CustomerPrimaryKey((string)item.CustomerId);
					if (!CustomerPrimaryKeys.Contains(newKey)) CustomerPrimaryKeys.Add(newKey);
					}
				}
				if((item.ParentCol.SubDomain.Contains(ACME.Northwind.Business.Collections.EmployeeCollection)) &&
					item.EmployeeItem == null)
				{
					if(item.EmployeeId != null)
					{
					EmployeePrimaryKey newKey = new EmployeePrimaryKey((int)item.EmployeeId);
					if (!EmployeePrimaryKeys.Contains(newKey)) EmployeePrimaryKeys.Add(newKey);
					}
				}
				if((item.ParentCol.SubDomain.Contains(ACME.Northwind.Business.Collections.ShipperCollection)) &&
					item.ShipperItem == null)
				{
					if(item.ShipVia != null)
					{
					ShipperPrimaryKey newKey = new ShipperPrimaryKey((int)item.ShipVia);
					if (!ShipperPrimaryKeys.Contains(newKey)) ShipperPrimaryKeys.Add(newKey);
					}
				}
			}
			bool handledError = false;

			if(CustomerPrimaryKeys.Count > 0)
			{
				CustomerSelectByPks retrieve = new CustomerSelectByPks(CustomerPrimaryKeys);
				this.SubDomain.AddSelectCommand(retrieve);
				handledError = true;
			}

			if(EmployeePrimaryKeys.Count > 0)
			{
				EmployeeSelectByPks retrieve = new EmployeeSelectByPks(EmployeePrimaryKeys);
				this.SubDomain.AddSelectCommand(retrieve);
				handledError = true;
			}

			if(ShipperPrimaryKeys.Count > 0)
			{
				ShipperSelectByPks retrieve = new ShipperSelectByPks(ShipperPrimaryKeys);
				this.SubDomain.AddSelectCommand(retrieve);
				handledError = true;
			}

			return handledError;
			}
			catch
			{
				throw;
			}
			finally
			{
				_handlingError = false;
			}
		}
		#endregion 

		#region Helper Methods

		internal virtual string GetPrimaryKeyXml()
		{
			return GetPrimaryKeyXml(((IEnumerable<ACME.Northwind.Business.Objects.Order>)new ACME.Northwind.Business.Objects.OrderCollection(this)).Select(x => x.PrimaryKey));
		}

		internal static string GetPrimaryKeyXml(ACME.Northwind.Business.Objects.OrderPrimaryKey primaryKey)
		{
			List<ACME.Northwind.Business.Objects.OrderPrimaryKey> list = new List<ACME.Northwind.Business.Objects.OrderPrimaryKey>();
			list.Add(primaryKey);
			return GetPrimaryKeyXml(new List<ACME.Northwind.Business.Objects.OrderPrimaryKey>(list));
		}

		internal static string GetPrimaryKeyXml(IEnumerable<ACME.Northwind.Business.Objects.OrderPrimaryKey> primaryList)
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("OrdersList");
			foreach(ACME.Northwind.Business.Objects.OrderPrimaryKey primaryKey in primaryList)
			{
				xWriter.WriteStartElement("Orders");
				xWriter.WriteStartElement("OrderID");
				xWriter.WriteString(primaryKey.OrderId.ToString());
				xWriter.WriteEndElement();
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}


		private string GetCustomerForeignKeyXml()
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("CustomersList");
			foreach(DomainOrder order in this)
			{
				xWriter.WriteStartElement("Customers");
				if(order.CustomerId != null)
				{
					xWriter.WriteStartElement("CustomerID");
					xWriter.WriteString(order.CustomerId.ToString());
					xWriter.WriteEndElement();
				}
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}


		private string GetEmployeeForeignKeyXml()
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("EmployeesList");
			foreach(DomainOrder order in this)
			{
				xWriter.WriteStartElement("Employees");
				if(order.EmployeeId != null)
				{
					xWriter.WriteStartElement("EmployeeID");
					xWriter.WriteString(order.EmployeeId.ToString());
					xWriter.WriteEndElement();
				}
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}


		private string GetShipperForeignKeyXml()
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("ShippersList");
			foreach(DomainOrder order in this)
			{
				xWriter.WriteStartElement("Shippers");
				if(order.ShipVia != null)
				{
					xWriter.WriteStartElement("ShipperID");
					xWriter.WriteString(order.ShipVia.ToString());
					xWriter.WriteEndElement();
				}
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}

		#endregion

		#region Methods

		#endregion

		#region IDisposable Members

		void IDisposable.Dispose()
		{
		}

		#endregion

	}
	#endregion

}
